package hongcaosp.app.android.user.settings.wallet.presenter;

import com.alibaba.fastjson.JSON;
import com.lzy.okgo.callback.AbsCallback;
import com.lzy.okgo.model.Response;

import hongcaosp.app.android.login.UserToken;
import hongcaosp.app.android.modle.BaseResponse;
import hongcaosp.app.android.modle.DataCallBack;
import hongcaosp.app.android.modle.impl.UserWalletModelImpl;
import hongcaosp.app.android.user.settings.wallet.iview.AccountBindIView;
import hongcaosp.app.android.user.settings.wallet.iview.WithdrawIView;
import xlj.lib.android.base.component.BasePresenter;
import xlj.lib.android.base.toastcompat.ToastManager;

/**
 * 提现
 */
public class WithdrawPresenter extends BasePresenter {

    private WithdrawIView view;

    private UserWalletModelImpl userWalletModel;

    public WithdrawPresenter(WithdrawIView view) {
        this.view = view;
        userWalletModel = new UserWalletModelImpl();
    }

    /**
     * 提现
     * @param type
     * @param amount
     */
    public void cashWithdrawal(int type, double amount) {
        userWalletModel.cashWithdrawal(UserToken.getDefault().getToken(), type, amount, new AbsCallback<BaseResponse>() {

            @Override
            public BaseResponse convertResponse(okhttp3.Response response) throws Throwable {
                try {
                    BaseResponse baseResponse = JSON.parseObject(response.body().string(), BaseResponse.class);
                    return baseResponse;
                } catch (Throwable e) {
                    throw e;
                }
            }

            @Override
            public void onSuccess(Response<BaseResponse> response) {
                if (response == null || response.code() != 200 || response.body() == null) {
                    ToastManager.getInstance().showToast("提现失败");
                    return;
                }
                view.cashWithdrawalRst(response.body());
            }
        });
    }
}
